class Grade < ActiveRecord::Base
  has_many :equivalent_grades,
    :class_name => 'Grade',
    :finder_sql => 'SELECT g.* FROM grades AS g, equivalent_grades AS ge WHERE g.id = ge.equivalent_to_id AND ge.grade_id = #{id}',
    :counter_sql => 'SELECT count(*) from equivalent_grades AS ge WHERE ge.grade_id = #{id}'

  has_many :educational_plans, :foreign_key => 'passing_grade_id'
  has_many :student_enrollments

  validates_presence_of :name, :abbreviation, :numerical_value, :ordering
  validates_numericality_of :numerical_value, :greater_than_or_equal_to => 0
  validates_numericality_of :ordering, :only_integer => true, :greater_than => -1
end
